/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.ViewOutStockSummary;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.ViewOutStockSummaryDao;
import com.ruipengkj.service.ViewOutStockSummaryService;
/**
 * 说明：
 * 商品采购汇总表Service层接口实现
 * @Author：李智深
 * @Date：2012-03-16
 */
@Service
public class ViewOutStockSummaryServiceImpl implements ViewOutStockSummaryService{

	@Resource
	private ViewOutStockSummaryDao ViewOutStockSummaryDao;//DAO层

	@Override
	public void deleteService(String id) throws Exception {
		
	}

	@Override
	public List<ViewOutStockSummary> findService(
			ViewOutStockSummary entity) throws Exception {
		return null;
	}

	@Override
	public ViewOutStockSummary getByIdService(String id)
			throws Exception {
		return null;
	}

	@Override
	public PageModel<ViewOutStockSummary> getScrollService(
			int firstResult, int maxResult, ViewOutStockSummary entity)
			throws Exception {
		String hql = "select o from ViewOutStockSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getHappenTime()!=null&& !entity.getHappenTime().equals("")){
					whereHQL.append("o.happenTime >=?").append(BaseQuery.AND);
					param.add(entity.getHappenTime());
			}
			if(entity.getEndTime()!=null&& !entity.getEndTime().equals("")){
				whereHQL.append("o.happenTime <=?").append(BaseQuery.AND);
				param.add(entity.getEndTime());
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewOutStockSummaryDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	@Override
	public void modifyService(ViewOutStockSummary entity)
			throws Exception {
		
	}

	@Override
	public void saveOrUpdateService(ViewOutStockSummary entity)
			throws Exception {
		
	}

	@Override
	public Serializable saveRetService(ViewOutStockSummary entity)
			throws Exception {
		return null;
	}

	@Override
	public void saveService(ViewOutStockSummary entity)
			throws Exception {
		
	}

	public ViewOutStockSummaryDao getViewOutStockSummary() {
		return ViewOutStockSummaryDao;
	}

	public void setViewOutStockSummaryDao(
			ViewOutStockSummaryDao ViewOutStockSummary) {
		this.ViewOutStockSummaryDao = ViewOutStockSummary;
	}
	
	@Override
	public List<ViewOutStockSummary> findExportService(
			ViewOutStockSummary entity) throws Exception {
		String hql = "select o from ViewOutStockSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
//			if(entity.getName()!=null&&!entity.getName().equals("")){
//				whereHQL.append("o.name").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
//				param.add("%"+entity.getName()+"%");
//			}
			if(null!=entity.getHappenTime()&&!("").equals(entity.getHappenTime())){
				whereHQL.append("HappenTime>=?").append(BaseQuery.AND);
				param.add(entity.getHappenTime());
			}
			if(null!=entity.getEndTime()&&!("").equals(entity.getEndTime())){
				whereHQL.append("HappenTime<=?").append(BaseQuery.AND);
				param.add(entity.getEndTime());
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewOutStockSummaryDao.findDao(hql, whereHQL.toString(), param, orderby);
	}
}
